package com.myjob.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.myjob.common.DubboConfig;
import com.myjob.config.MjServiceName;
import com.myjob.entity.Company;
import com.myjob.entity.Hr;
import com.myjob.handler.CompanyHandler;
import com.myjob.handler.HrHandler;
import com.myjob.handler.testHandler;
import com.myjob.response.Result;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * @author Chen Yuan
 * @create 2021-01-27  19:08
 */
@RestController
@Slf4j
public class TestController {
	// 调用 user 服务中的方法
	@Reference(group = MjServiceName.COMPANY, version = DubboConfig.VERSION)
	private testHandler testHandler;
	@Reference(group = MjServiceName.COMPANY, version = DubboConfig.VERSION)
	private CompanyHandler companyHandler;
	@Reference(group = MjServiceName.COMPANY, version = DubboConfig.VERSION)
	private HrHandler hrHandler;

	@GetMapping("/test")
	@GlobalTransactional(rollbackFor = Exception.class)
	public Result selectCompanies(String companyId,
	                              String hrId,
								  Integer postNumber){
		Result result = null;

		log.info("[Dubbo] - 远程调用开始 -> companyHandler -> updateCompany");
		Company company = new Company();
		company.setCompanyId(companyId);
		company.setPostNumber(postNumber);
		companyHandler.updateCompany(company);
		log.info("[Dubbo] - 远程调用结束 -> ===============================");
		int i = 1 / 0;
		log.info("[Dubbo] - 远程调用开始 -> hrHandler -> updateHr");
		Hr hr = new Hr();
		hr.setUserId(hrId);
		hr.setJobNumber(postNumber);
		hrHandler.updateHr(hr);
		log.info("[Dubbo] - 远程调用结束 -> ===============================");

		return result;
	}

}
